<template>
	<view class="">
		<view class="count" :style="'padding-top:'+statusBarHeight+'px'">
			<view class="left" v-if="headShow">
				<text class="icon iconfont icon-zuojiantou2 icon1" style="color: #000;" @tap="Back(2)"></text>
			</view>
			<view class="left" v-else>
				<text class="icon iconfont icon-zuojiantou2 icon1" @tap="left"></text>
			</view>
			<view class="center" v-if="headShow">
				<view class="count-title">
					<text>{{countObj.BEDID}}</text>
					<text>{{countObj.PNAME}}</text>
					<text>{{countObj.PSEX}}</text>
					<text>{{countObj.MRN}}</text>
				</view>
				<view class="count-input" v-html="`过敏史：${passObj.pallergy? passObj.pallergy : '无'}`">
					<!-- 过敏史：甲硝唑过敏全身瘙痒口服甲硝唑全身发痒其它(一般过敏)未发现\r\n青霉素皮试皮试阴性（-） 2022/11/21 13:38:18\r\n -->
				</view>
			</view>
			<view class="center" v-else>
				<view class="count-title count-title1">
					{{countObj.PNAME}}
				</view>
				<view class="count-input" style="justify-content: space-evenly; color: #FEFF87;">
					<text>{{countObj.BEDID}}</text>
					<text>{{countObj.PSEX}}</text>
					<text>{{countObj.MRN}}</text>
				</view>
			</view>
			<view class="right" v-if="!headShow">
				<view v-if="num" class="img2 viewSkj" @tap.stop="viewNum">
					<u-image src="../../static/img/date.svg" width="28px" height="28px" style="align-items: center;">
					</u-image>
					<view class="viewtxet">{{choiceName}}</view>
				</view>
				<text v-else class="icon iconfont icon-zuojiantou2 icon1" @tap="right"></text>
			</view>
		</view>
		<Choice v-if="shows" @choiceFun="choiceFun" :valueIndex="valueIndex"></Choice>
	</view>

</template>

<script>
	import {
		mapMutations,
		mapState
	} from "vuex";
	import Choice from './choice.vue'
	import {
		Ward_GetPatBedList_IIS
	} from '../../api/user.js'
	export default {
		props: {
			num: {
				type: Boolean
			},
			headShow: {
				type: Boolean,
				default: false
			}
		},
		// props: ['num',
		// headShow:{

		// }],
		data() {
			return {
				numIndex: 0,
				countObj: {},
				countArray: [],
				examinationType: 1,
				shows: false,
				choiceName: '今天',
				valueIndex: '1',
				statusBarHeight: 24, //状态栏高度
			};
		},
		components: {
			Choice
		},
		computed: {
			...mapState('user', ["deleteObj", "deleteArr", "passObj", "userInfo"])
		},
		async mounted() {
			let arr = uni.getStorageSync('passObj') ? uni.getStorageSync('passObj') : uni.getStorageSync('deleteObj')
			console.log(arr);
			this.countArray = uni.getStorageSync('deleteArr')
			if (uni.getStorageSync('passObj') !== '') {
				this.countObj = this.countArray.find((item) => {
					return item.PNAME == arr.pname
				})
				if (!this.countObj) {
					//
					const user = uni.getStorageSync('userInfo')
					const res = await this.$http.Ward_GetPatBedList_IIS({
						HosKind: user.hoscode,
						sOperdept: user.HosKind
					})
					if (res) {
						let Array = res.map((item, index) => ({
							...item,
							PSEX: item.PSEX == 'F' ? '女' : '男',
							CARETYPE: item.CARETYPE == '0' ? '特' : item.CARETYPE == '1' ? 'Ⅰ' : item
								.CARETYPE == '2' ? 'Ⅱ' : item.CARETYPE == '3' ? 'Ⅲ' : '',
							ids: index
						}))

						this.countObj = Array.find((item) => {
							return item.PNAME == arr.pname
						})

						this.set_deleteArr(Array)

						if (!this.countObj) {
							uni.showToast({
								title: "查询不到该病人信息！", //显示的文字
								duration: 2000, //显示多少时间，默认1500毫秒
								icon: "none", //自定义显示的图标，默认成功success，错误error,加载loading，不显示图标是none
								mask: true,
								success() {
									setTimeout(() => {
										uni.navigateBack()
									}, 2300)
								}
							})
							return
						}
					}
				}
			} else {
				this.countObj = arr
			}
			this.set_deleteObj(this.countObj)
			// console.log('头部', this.countObj);
		},
		methods: {
			...mapMutations("user", ["set_deleteObj", "set_deleteArr"]),
			Back(data) {
				//uni.navigateBack()//默认delta:1
				uni.navigateBack({
					delta: 1, //返回层数，2则上上页
				})
			},
			left() {
				if (uni.getStorageSync('passObj') !== '') {
					console.log(1);
					return
				}
				if (this.countObj.ids == 0) {
					return uni.$u.toast('前面没有更多了')
				} else {
					this.numIndex = this.countObj.ids;
					this.numIndex--;
					this.countObj = this.countArray[this.numIndex]
					// return
				}
				this.set_deleteObj(this.countObj)
			},
			right() {
				if (uni.getStorageSync('passObj') !== '') {
					return
				}
				if (this.countObj.ids == (this.countArray.length - 1)) {
					return uni.$u.toast('后面没有更多了')
				} else {
					this.numIndex = this.countObj.ids;
					this.numIndex++;
					this.countObj = this.countArray[this.numIndex]
					// return
				};
				// console.log(this.countObj);
				this.set_deleteObj(this.countObj)
			},
			choiceFun(e, vaule) {
				this.valueIndex = e.value
				this.choiceName = e.label
				this.shows = vaule
				this.$emit('hedafun', this.choiceName);
			},
			viewNum() {
				this.shows = !this.shows
			}
		}
	}
</script>

<style lang="scss" scoped>
	.count {
		height: 78px;
		background: #7AD9DF;
		// padding: 0 25px;
		display: flex;
		// flex-direction: column;
		// justify-content: space-evenly;
		position: relative;
	}

	.count-title1 {
		justify-content: center !important;
		// margin-bottom: 10px !important;
		font-size: 24px;
		color: #FEFF87;
	}

	.count-title {
		display: flex;
		justify-content: space-between;
		margin-bottom: 3px;

		text {
			margin: 0 5px;
			font-size: 16px;
			font-family: SourceHanSansCN-Medium, SourceHanSansCN;
			font-weight: 500;
			color: #FEFF87;
			line-height: 27px;
		}

		.count-text {
			font-size: 20px !important;
		}
	}

	.count-input {
		display: flex;
		margin: 0 auto;
		font-size: 14px;
		font-family: SourceHanSansCN-Medium, SourceHanSansCN;
		font-weight: 500;
		color: red;
		line-height: 16px;
		padding: 0 10px;

		text {
			margin: 0 36rpx;
			font-size: 34rpx;
			font-family: SourceHanSansCN-Medium, SourceHanSansCN;
			font-weight: 500;
			color: #FEFF87;
			line-height: 27px;
		}
	}

	.count-input1 {
		display: flex;
		justify-content: center;
		width: 207px;
		height: 22px;
		// border-radius: 4px;
		// border: 1px solid #A8E8EC;
		margin: 0 auto;
		font-size: 18px;
		font-family: SourceHanSansCN-Medium, SourceHanSansCN;
		font-weight: 500;
		color: red;
		line-height: 24px;
		padding: 0 10px;
	}

	.viewSkj {
		display: flex;
		flex-direction: column;
		width: 50px;

		.viewtxet {
			margin-top: 6px;
			font-size: 16px;
			font-family: SourceHanSansCN-Medium, SourceHanSansCN;
			font-weight: 500;
			color: #FF4D65;
			text-align: center;
			line-height: 24px;
		}
	}

	.center {
		width: 71%;
		overflow: hidden;
	}

	.left {
		width: 16%;
		display: flex;
		justify-content: center;
		align-items: center;

		.icon1 {
			color: #C3FAFC;
			font-size: 24px !important;
		}
	}

	.right {
		width: 16%;
		display: flex;
		justify-content: center;
		align-items: center;

		.icon1 {
			color: #C3FAFC;
			font-size: 24px !important;
			transform: rotate(180deg);
		}
	}

	::v-deep.u-border {
		border: 1px solid #B3E7EA;
		border-color: #B3E7EA !important;
	}
</style>
